|
|
|
|
|
|
|
Here are a couple of Boolean expressions: |
|
|
|
|
|
|
|
|
Dim A As Boolean, B As Boolean
A = True
B = Not True |
|
|
|
|
|
|
|
|
What is the value of B? False, of course. It's logical: Anything that is not True must be False. Boolean algebra is a lot like thatmostly common sense. |
|
|
|
|
|
|
|
|
We use a special kind of table, called a truth table, to determine the results of a Boolean operation. The truth table for the NOT operation is shown below: |
|
|
|
|
| VARIABLE A | RESULT (NOT A) | | True | False | | False | True | | The NOT Operation |
|
|
|
|
|
|
The first column contains all of the possible values for the variable. The result is what you get after you apply the operation. Thus, Not True = False, Not False = True. |
|
|
|
|
|
|
|
|
The NOT operator is the easiest one. There are three Boolean operators in Visual Basic that use two variables: the AND, OR, and XOR operators. |
|
|
|
|
|
|
|
|
The truth tables for these operators are as follows: |
|
|
|
|
| VARIABLE A | VARIABLE B | RESULT (A AND B) | | False | False | False | | False | True | False | | True | False | False | | True | True | True | | The AND Operation | | | | VARIABLE A | VARIABLE B | RESULT (A OR B) | | False | False | False | | False | True | True | | True | False | True | | True | True | True | | The OR Operation | | |
|
|
|